home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: (void(far *)()) 0
- Date: Fri, 09 Feb 96 00:38:55 GMT
- Organization: none
- Message-ID: <823826335snz@genesis.demon.co.uk>
- References: <341998718.10858110@magnet.at> <31165B9D.398E@imsisoft.com> <4f66c0$cn0@solutions.solon.com> <3118F813.41BF@imsisoft.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <3118F813.41BF@imsisoft.com>
- vbazarov@imsisoft.com "Victor Bazarov" writes:
-
- >Peter Seebach wrote:
- >>
- >> In article <31165B9D.398E@imsisoft.com>,
- >> Victor Bazarov <vbazarov@imsisoft.com> wrote:
- >> >> .... = (void(far *)()) 0;
- >>
- >> >> Now I want to know if my assumption is right and
- >> >> in case it is, what does this mean for 0 ?
- >>
- >> >Nothing but what you've said -- cast. '0' has type 'int',
- >> >and must be converted into pointer to function in order
- >> >to be properly assigned.
- >>
- >> Not exactly.
- >>
- >> 0 is a special case. Zero cast to a pointer type is a null pointer of that
-
- In fact an integral constant expression in a context that requires a pointer
- is implicitly converted to a null pointer of that type - no cast is required,
- e.g.
-
- char *ptr = 0;
-
- initialised ptr to the char * null pointer.
-
- >> type. Or rather, *a constant zero* is. An integer with value zero may
- >> produce different results.
- >
- >As I undestood, this "may produce different results":
- >
- >typedef void (far *pVOIDVOID)();
- >int zero = 0;
- >pVOIDVOID funky;
- >funky = (void(far *)()) zero;
- >
- >than
- >
- >typedef void (far *pVOIDVOID)();
- >pVOIDVOID funky;
- >funky = (void(far *)()) 0;
- >
- >?
-
- Exactly. The compiler can only perform the 'magic' if it sees 0 as the result
- of a constant expression at compile time. 0 is an integral constant expression
- whereas zero is not (even if it was defined as const int).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-